
<%@page import="java.util.Date" %>
<%@ page import="org.dj.eoms.core.util.DateUtil" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>企业运营管理系统</title>

<link rel="stylesheet" type="text/css" href="<%=path%>/resources/ext4/resources/css/ext-all.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/resources/ext4/resources/css/ext-msg.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/resources/css/icons.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/resources/css/sytle.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/resources/css/ext_chinese_font.css">
<style type="text/css">
    .x-unselectable {
        cursor: pointer;
    }

</style>
<script type="text/javascript" src="<%=path%>/resources/ext4/ext-all-debug.js"></script>
<script type="text/javascript" src="<%=path%>/resources/ext4/locale/ext-lang-zh_CN.js"></script>
<script type="text/javascript" src="<%=path%>/resources/js/helper/windowHelper.js"></script>
<script type="text/javascript" src="<%=path%>/resources/js/helper/msgHelper.js"></script>
<script type="text/javascript" src="<%=path%>/resources/js/helper/city.js"></script>
<script type="text/javascript" src="<%=path%>/resources/ext/resources/Ext.util.TaskRunner.js"></script>
<script type="text/javascript" src="<%=path%>/resources/ext/resources/Ext.util.TaskRunner.Task.js"></script>
<script type="text/javascript" src="<%=path%>/resources/js/helper/awaitMsg.js"></script>
<link rel="stylesheet" type="text/css" href="<%=path%>/resources/css/awaitMsg.css">
<script>

Ext.Loader.setConfig({enabled: true});

Ext.Loader.setPath('Ext.ux', "<%=path%>/resources/ext4/ux");

Ext.require([
    'Ext.tab.*',
    'Ext.ux.TabCloseMenu',
    'common.windowHelper',
    'common.msgHelper',
    'Ext.ux.RowExpander'
]);

//系统全局对象,用于页面间参数传递
var globalParameter = null;
/**
 * 退出系统
 * 该请求地址由spring-security实现
 */
function MainLogout(btn) {
    if (btn == 'yes') {
        Ext.Ajax.request({
            url: '<%=path%>/logout.do',
            method: 'POST',
            success: function (response) {
                location.href = "<%=path%>";
            },
            failure: function (xhr) {
                if (Ext.isEmpty(xhr.responseText))
                    common.msgHelper.msg("系统异常", "请求超时,请稍后再试");
                else
                    common.msgHelper.msg("提示", "系统异常:退出失败");
            }
        });
    }
}

Ext.onReady(function () {

    //弹出式描述功能初始化
    Ext.QuickTips.init();

    //使用cookie保存用户设置信息
    Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));


    /////////////////////////////菜单数据源
    var accordionItems = [];
    var accordionStore = Ext.create('Ext.data.ArrayStore', {
        fields: ['resId', 'resName', 'icon', 'cls', 'parentid', 'url', 'isFolder', 'isOpen', 'leafNum'
        ],
        proxy: {
            type: 'ajax',
            url: '<%=path%>/framework/webappmain/findAccordionMenuData.do',
            extraParams: {webAppCode: 'CRM'}
        },
        autoLoad: true
    });
    accordionStore.load({
        callback: function (records, operation, success) {
            var i = 0;
            Ext.each(records, function (menuObj) {
                var accordionItem = {title: menuObj.get('resName'), icon: menuObj.get('icon')};
                if (menuObj.get('leafNum') > 0) {
                    getMenuData(accordionItem, menuObj.get('resId'));
                }
                accordionItems[i] = accordionItem;
                i++;
            });
            // 渲染框架布局
            createmainViewport();
        }
    });


    //////////////框架布局
    function createmainViewport() {
        //创建全景视图端
        var viewport = Ext.create('Ext.Viewport', {
            id: 'crm-mainView',
            layout: 'border',//框式布局
            items: [
                // 创建一个通用组建实例
                Ext.create('Ext.Component', {
                    region: 'north',
                    height: 70, // give north and south regions a height
                    autoEl: {
                        tag: 'div',
                        html: "<table border='0' style='width:100%;height:100%;'>" +
                                "<tr><td style=\"width:100%;height:72px\">\n" +
                                "			                    <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"width:100%;height:100%\">\n" +
                                "			                        <tr>\n" +
                                "			                        	<td rowspan=\"2\">\n" +
                                "			                                <img src=\"<%=path%>/resources/images/main/main.jpg\" border=\"0\"/>\n" +
                                "			                            </td>\n" +
                                "			                            <td align=\"right\">登录时间:<%=DateUtil.formatDate(new Date(),"yyyy-MM-dd HH:mm") %>&nbsp;\n" +
                                "			                                <a href=\"#\" onclick=\"Ext.MessageBox.confirm('确定', '确定要退出系统吗?', MainLogout)\" style='text-decoration:none;'><font color='#0000FF'>退出</font></a>&nbsp;&nbsp;\n" +
                                "			                            </td>\n" +
                                "			                        </tr>\n" +
                                "			                        <tr>\n" +
                                "			                            <td valign=\"middle\" align=\"right\">\n" +
                                "			                                <img src=\"<%=path%>/resources/images/main/Profile.png\" width=\"14\" height=\"14\" border=\"0\"/>\n" +
                                "			                            		当前用户：&nbsp;&nbsp;&nbsp;&nbsp;\n" +
                                "			                            <a href=\"javascript:void(0)\" onclick=\"openChangePwdWin()\" style='text-decoration:none;'><font color='#0000FF'>修改密码</font></a>\n" +
                                "			                            &nbsp;&nbsp;\n" +
                                "			                            </td>\n" +
                                "			                        </tr>\n" +
                                "			                    </table>\n" +
                                "							</td></tr>" +
                                "</table>"
                    }
                }),
                Ext.create('Ext.Toolbar', {
                    region: 'south',
                    height: 30,
                    items: ["技术支持:<a href=\"javascript:void(0)\"  style='text-decoration:none;'><font color='#0000FF'>Dean Joson</font></a>&nbsp;&nbsp;", '->', "<a href=\"javascript:showImprint()\"  style='text-decoration:none;'><font color='#0000FF'>版本更新说明</font></a>&nbsp;&nbsp;"]

                }),
                {
                    region: 'west',
                    stateId: 'navigation-panel',
                    id: 'west-panel', // see Ext.getCmp() below
                    title: '企业运营管理系统',
                    iconCls: 'icon-house',
                    split: true,
                    width: 200,
                    minWidth: 175,
                    maxWidth: 400,
                    collapsible: true,
                    animCollapse: true,
                    margins: '0 0 0 5',
                    layout: 'accordion',
                    items: accordionItems

                },
                Ext.create('Ext.tab.Panel', {
                    id: 'sysTabPanel',
                    region: 'center', //中心区在框布局中是必须定义的
                    deferredRender: false,
                    activeTab: 0,     //设置第一个选项卡为默认显示的

                    items: [
                        {
                            id: 'homeTabPage',
                            title: '我的主页',
                            iconCls: '',
                            autoScroll: true,
                            autoHeight: true,
                            active: true,//为了兼容IE9
                            fit: true,
                            loader: {
                                url: '<%=path%>/framework/webappmain/welcomePage.do',
                                contentType: 'html',
                                loadMask: true,
                                scripts: true,
                                autoLoad: true
                            }
                        }
                    ],
                    plugins: Ext.create('Ext.ux.TabCloseMenu', {
                        extraItemsTail: [
                            '-',
                            {
                                text: 'Closable',
                                checked: true,
                                hideOnClick: true,
                                handler: function (item) {
                                    currentItem.tab.setClosable(item.checked);
                                }
                            },
                            '-',
                            {
                                text: 'Enabled',
                                checked: true,
                                hideOnClick: true,
                                handler: function (item) {
                                    currentItem.tab.setDisabled(!item.checked);
                                }
                            }
                        ],
                        listeners: {
                            aftermenu: function () {
                                currentItem = null;
                            },
                            beforemenu: function (menu, item) {
                                menu.child('[text="Closable"]').setChecked(item.closable);
                                menu.child('[text="Enabled"]').setChecked(!item.tab.isDisabled());

                                currentItem = item;
                            }
                        }
                    })



                })
            ]
        });
    }

});


/**
 * 根据手风琴菜单编码生成菜单树
 * @param accordionItem 手风琴项
 * @param superMenuId
 */
function getMenuData(accordionItem, superMenuId) {
    ////////////////////菜单树数据源
    var menuStore = Ext.create('Ext.data.TreeStore', {
        fields: ['id', 'text', 'leaf', 'icon', 'cls', 'parentid', 'url', 'isFolder', 'isOpen'
        ],
        proxy: {
            type: 'ajax',
            url: '<%=path%>/framework/webappmain/getMenuTreeData.do',
            extraParams: {webAppCode: 'CRM', superMenuId: superMenuId}
        },
        sorters: [
            {
                property: 'leaf',
                direction: 'ASC'
            },
            {
                property: 'sn',
                direction: 'ASC'
            }
        ]
    });

    var tree = Ext.create('Ext.tree.Panel', {
        id: superMenuId + 'tree',
        store: menuStore,
        border: false,
        rootVisible: false,
        useArrows: true,
        frame: true,
        height: 1000,
        //width:'100%',
        listeners: {//tree节点事件监听器
            //当点击节点时，执行函数：
            'itemclick': function (view, selectedItem) {
                if (selectedItem.data.leaf) {
                    common.windowHelper.addTabs(selectedItem.data.id, selectedItem.data.text, "<%=path%>" + selectedItem.data.url);
                }
            }
        }
    });
    accordionItem.items = tree;
}


/**
 * @category 查看版本说明--miss
 */
function showImprint() {

    var win = Ext.create('Ext.Window', {
        closable: true,
        plain: true,
        modal: true,
        autoScroll: true,
        closeAction: 'destroy',
        layout: 'fit',
        id: 'crm_main_imprint_detailWin',
        title: '版本更新说明',
        width: 950,
        height: 500,
        active: true,
        minHeight: 200,
        loader: {
            url: '<%=path %>/framework/webappmain/getImprintPage.do',
            contentType: 'html',
            autoLoad: true,
            scripts: true,
            loadMask: true
        }, buttons: [
            {
                text: '关闭',
                iconCls: "icon-cancel",
                handler: function () {
                    Ext.getCmp('crm_main_imprint_detailWin').destroy();
                }
            }
        ]
    });
    win.show();
}

//修改密码--miss
function openChangePwdWin() {
    var win = Ext.create('Ext.Window', {
        closable: true,
        plain: true,
        modal: true,
        autoScroll: true,
        closeAction: 'destroy',
        layout: 'fit',
        id: 'common-editePwd-Win',
        title: '修改密码',
        width: 310,
        height: 160,
        active: true,//为了兼容IE9
        fit: true,
        loader: {
            url: '<%=path%>/framework/webappmain/changePwdPag.do',
            contentType: 'html',
            autoLoad: true,
            scripts: true,
            loadMask: true
        }
    });
    win.show();
}

</script>
</head>
<body>
<div id="west" class="x-hide-display"></div>
<div id="center" class="x-hide-display"></div>
</body>
</html>